<template>
  <div class="p-2">
    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd"
              v-hasPermi="['live:activity:add']">登录</el-button>
          </el-col>
        </el-row>
      </template>
    </el-card>
    <!-- 添加或修改活动管理对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
      <el-image :src="loginQrCode"></el-image>
    </el-dialog>
  </div>
</template>

<script setup name="boosPush" lang="ts">
  const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  import { randQrCode, scan } from '@/api/boss/push';

  const dialog = reactive<DialogOption>({
    visible: false,
    title: ''
  });

  const loginQrCode = ref('');

  /** 新增按钮操作 */
  const handleAdd = async () => {
    const res = await randQrCode();
    console.log(res)

    if (res.data && res.data.qrCodeImg.length > 0) {
      loginQrCode.value = 'data:image/png;base64,' + res.data.qrCodeImg

      dialog.visible = true;
      dialog.title = "登录";

      scanCode(res.data.qrId);
    } else {
      proxy?.$modal.msgError('生成登录二维码失败');
    }
  }

  const scanCode = (uuid) => {
    scan(uuid);
  }

  onMounted(() => {
  });
</script>
